import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path';
import posstcssPxToViewport from 'postcss-px-to-viewport'


// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
 css:{
  postcss:{
    plugins:[
      posstcssPxToViewport({
        viewportWidth:667,
        viewportUnit:'vw',
      })
    ]
  }
 },
  
  server:{
   hmr:true,
   
   //登录
   proxy:{
    
   '/api':{
     target:'http://124.221.74.149:3000/',
     changeOrigin:true,
     rewrite: (path) => path.replace(/^\/api/, '')
   },
   '/getAIToken':{
      target:'https://qianfan.baidubce.com/v2/app/conversation',
      changeOrigin:true,
      rewrite: (path) => path.replace(/^\/getAIToken/, '')
   },
   '/chat':{
    target:'https://qianfan.baidubce.com/v2/app/conversation/runs',
    changeOrigin:true,
    rewrite: (path) => path.replace(/^\/chat/, '')
   },
   '/yy':{
      target:'http://vop.baidu.com/server_api',
      changeOrigin:true,
      rewrite: (path) => path.replace(/^\/yy/, '')
   },
   '/tts':{
         target:'https://tsn.baidu.com/text2audio',
         changeOrigin:true,
         rewrite: (path) => path.replace(/^\/tts/, '')
   },
   '/token':{
     target:'https://aip.baidubce.com/oauth/2.0/token',
     changeOrigin:true,
     rewrite: (path) => path.replace(/^\/token/, '')
   },
     //ai接口
     '/aibox':{
      target:'http://localhost:8090',
      changeOrigin:true,
      rewrite: (path) => path.replace(/^\/ai/, '')
     }
   },
 
  },
  build:{
    minify:'esbuild',
    assetsDir:'./assets',
    chunkSizeWarningLimit:500,
    //如果设置为false,整个项目中所有的css都会被打包到一个css文件中
    cssCodeSplit:true,
  }
})
